

#include "stdafx.h"
#include "pf_utility.h"


/**
 * Converts a double to a string cutting away unnecessary 0's.
 * e.g. 2.70000  -> 2.7
 */
QString PF_Utility::doubleToString(double value, int precision) {
    QString ret;

    ret.setNum(value, 'f', precision);

    if(ret.contains('.')) {
        // remove trailing zeros:
        while(ret.at(ret.length()-1)=='0') {
            ret.truncate(ret.length()-1);
        }

        // remove trailing .
        if(ret.at(ret.length()-1)=='.') {
            ret.truncate(ret.length()-1);
        }
    }

    return ret;
}

// EOF

